/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Structures;

import java.io.File;
import java.io.Serializable;

/**
 *
 * @author Mariusz
 */
public class BiedronkaProfile extends ReceiptProfile implements Serializable {

    public BiedronkaProfile() {
        super("Biedronka");
        this.addTrainingImage(new File("./pliki/biedronka/Biedronka_Cyfry.png"), '0', '9');
        this.addTrainingImage(new File("./pliki/biedronka/Biedronka_Duze.png"), 'A', 'Z');
        this.addTrainingImage(new File("./pliki/biedronka/Biedronka_Male.png"), 'a', 'z');
        this.addTrainingImage(new File("./pliki/biedronka/Biedronka_plus przecinek myslnik kropka.png"), '+', '.');
        this.addTrainingImage(new File("./pliki/biedronka/Biedronka_spacja wykrzyknik cudzyslow hasz.png"), ' ', '#');
    }

    @Override
    public boolean isDefault() {
        return true;
    }
    
    @Override
    public boolean checkIfProduct(String p) {
        return p.matches(".+[ABC8]{1}.+[x]{1}.+[ABC8]{1}\\s{1}") ? true : false;
    }

    @Override
    public Entry getProduct(String s) {
        Entry product = new Entry();
        
        String[] temp = s.split("\\s{1}[ABC8]{1}\\s+", 2);

        temp[1] = temp[1].replace('o', '0');
        temp[1] = temp[1].replace('O', '0');
        temp[1] = temp[1].replace('i', '1');
        temp[1] = temp[1].replace('I', '1');
        temp[1] = temp[1].replace('l', '1');
        temp[1] = temp[1].replace('L', '1');

        String priceAmount = temp[1].substring(0, temp[1].indexOf(' '));
        String[] separateAmountAndPrice = priceAmount.split("x", 2);
        separateAmountAndPrice[0] = separateAmountAndPrice[0].replaceAll("[^0-9]", "");
        separateAmountAndPrice[1] = separateAmountAndPrice[1].replaceAll("[^0-9]", "");
        if (separateAmountAndPrice[0].length() >= 4) {
            separateAmountAndPrice[0] = new StringBuffer(
                    separateAmountAndPrice[0]).insert(separateAmountAndPrice[0].length() - 3, '.').toString();

        }
        separateAmountAndPrice[1] = new StringBuffer(
                separateAmountAndPrice[1]).insert(separateAmountAndPrice[1].length() - 2, '.').toString();

        product.name = temp[0];
        product.price = Float.parseFloat(separateAmountAndPrice[1]);
        product.quantity = Float.parseFloat(separateAmountAndPrice[0]);
        
        return product;
    }
}
